package 华为OD机试B卷复用题.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ20_最长方连续方波信号 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/进阶题/input/20.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        String s = in.nextLine();
        StringBuilder tmp = new StringBuilder();
        String res = "";
        int start = 0;
        // 先找出第一个 0
        while (s.charAt(start) != '0' && start < s.length()) {
            start++;
        }
        tmp.append(0);
        boolean isFormat = true;
        // 开始解析 s
        for (int i = start + 1; i < s.length(); i++) {
            char before = s.charAt(i - 1);
            char now = s.charAt(i);
            if (now == before) {
                if (now == '1') {
                    // 已经不是完全交替了
                    isFormat = false;
                    // 这一步没必要做，但它也是一个信号
                    tmp.append(now);
                } else {
                    String tmpToString = tmp.toString();
                    if (isFormat && tmpToString.length() > res.length()) {
                        res = tmpToString;
                    }
                    isFormat = true;
                    tmp = new StringBuilder("0");
                }
            } else {
                tmp.append(now);
            }
        }
        if (res.length() > 0) {
            System.out.println(res);
        } else {
            System.out.println(-1);
        }
    }
}
